using System;
using System.Windows.Forms;

using DirkRettschlag.Utils;

namespace Departure
{
    public partial class frmSettings : Form
    {
        #region Variables

        GeneralSettings generalSettings;

        #endregion Variables

        #region Properties

        public GeneralSettings GeneralSettings
        {
            get { return this.generalSettings; }
            set { this.generalSettings = value; }
        }

        #endregion Properties

        #region Constructor

        public frmSettings()
        {
            InitializeComponent();

            this.generalSettings = new GeneralSettings();

            this.tbcSettingsMain.Top = 0;
            this.tbcSettingsMain.Left = 0;
            this.tbcSettingsMain.Height = this.ClientSize.Height;
            this.tbcSettingsMain.Width = this.ClientSize.Width;

            this.labelCountdownTrainFormatDesc.Text = "Description:\r\n\r\n%TI%\t- Time\r\n%TR%\t- Train\r\n%DI%\t- Direction\r\n%PL%\t- Platform";

            this.generalSettings.getSettings();
            this.setControls();

        }

        #endregion Constructor

        #region Private Methods

        private void setControls()
        {
            this.chkAutoUpdate.Checked = this.generalSettings.AutoUpdate;
            this.numericUpDownUpdateStations.Value = (decimal)this.generalSettings.UpdateInterval;
            this.chkWAP.Checked = this.generalSettings.UseWAP;
            this.chkAutoConnect.Checked = this.generalSettings.AutoConnect;
            this.textBoxHttpHeader.Text = this.generalSettings.HTTPHeader;
            this.textBoxUserAgent.Text = this.generalSettings.UserAgent;
            this.chkRemovePastDepartures.Checked = this.generalSettings.RemovePastDepartures;
            this.textBoxCountdownTrainFormat.Text = this.generalSettings.CountdownTrainFormat;
        }

        private void setGeneralSettings()
        {
            this.generalSettings.AutoUpdate = chkAutoUpdate.Checked;
            this.generalSettings.UpdateInterval = (double)numericUpDownUpdateStations.Value;
            this.generalSettings.UseWAP = chkWAP.Checked;
            this.generalSettings.AutoConnect = chkAutoConnect.Checked;
            this.generalSettings.HTTPHeader = textBoxHttpHeader.Text;
            this.generalSettings.UserAgent = textBoxUserAgent.Text;
            this.generalSettings.RemovePastDepartures = chkRemovePastDepartures.Checked;
            this.generalSettings.CountdownTrainFormat = textBoxCountdownTrainFormat.Text;
        }
        
        private void mniSave_Click(object sender, EventArgs e)
        {
            this.setGeneralSettings();
            this.generalSettings.saveSettings();
            this.Close();
        }

        private void mniCancel_Click(object sender, EventArgs e)
        {
            this.generalSettings.getSettings();
            this.setControls();
            this.Close();
        }

        private void inputPanel_EnabledChanged(object sender, EventArgs e)
        {
            if (this.inputPanel.Enabled)
            {
                this.tbcSettingsMain.Height -= this.inputPanel.Bounds.Height;
            }
            else
            {
                this.tbcSettingsMain.Height = this.ClientSize.Height;
            }
        }

        #endregion Private Methods
    }
}
